/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MemberListPanel.java
 *
 * Created on Oct 19, 2011, 11:03:29 AM
 */
package teletutor.classroommanager.UI;

import teletutor.classroommanager.services.MemberProxy;
import java.awt.FlowLayout;
import javax.swing.SwingUtilities;
import teletutor.classroommanager.services.ClassroomManager;

/**
 *
 * @author Rae
 */
public class MemberListPanel extends javax.swing.JPanel {

    ClassroomManager crman;

    /** Creates new form MemberListPanel */
    public MemberListPanel(ClassroomManager crman) {
        initComponents();
        this.crman = crman;
        listPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));
        
        // if this is the tutor, do not show the "leave a note" fields at the
        // bottom
        if (crman.isOnTutorNode()) {
            curiousButton.setVisible(false);
            curiousNoteEdit.setVisible(false);
        }
    }

    public void addMember(final MemberProxy mProxy) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                listPanel.add(mProxy.getThumbPanel());
                listPanel.revalidate();
            }
        });
    }

    public void removeMember(final MemberProxy mProxy) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                listPanel.remove(mProxy.getThumbPanel());
                listPanel.revalidate();
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        scrollPane = new javax.swing.JScrollPane();
        listPanel = new javax.swing.JPanel();
        curiousButton = new javax.swing.JButton();
        curiousNoteEdit = new javax.swing.JTextField();

        jLabel1.setText("List of Members:");

        scrollPane.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        listPanel.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout listPanelLayout = new javax.swing.GroupLayout(listPanel);
        listPanel.setLayout(listPanelLayout);
        listPanelLayout.setHorizontalGroup(
            listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 677, Short.MAX_VALUE)
        );
        listPanelLayout.setVerticalGroup(
            listPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 416, Short.MAX_VALUE)
        );

        scrollPane.setViewportView(listPanel);

        curiousButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/memberThumb/question32x32.png"))); // NOI18N
        curiousButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        curiousButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                curiousButtonActionPerformed(evt);
            }
        });

        curiousNoteEdit.setFont(new java.awt.Font("Cambria", 0, 17)); // NOI18N
        curiousNoteEdit.setText("Leave a note to the tutor...");
        curiousNoteEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                curiousNoteEditActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(curiousNoteEdit, javax.swing.GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(curiousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(curiousNoteEdit, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(curiousButton, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void curiousButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_curiousButtonActionPerformed
        String cmsg = curiousNoteEdit.getText();
        MemberProxy mp = crman.getMemberProxy(crman.getChannel().getChannelName());
        mp.setNote(cmsg);
        mp.setState(MemberProxy.STUDENT_CURIOUS);
        curiousNoteEdit.setText("");
    }//GEN-LAST:event_curiousButtonActionPerformed

    private void curiousNoteEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_curiousNoteEditActionPerformed
        curiousButtonActionPerformed(null);
    }//GEN-LAST:event_curiousNoteEditActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton curiousButton;
    private javax.swing.JTextField curiousNoteEdit;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel listPanel;
    private javax.swing.JScrollPane scrollPane;
    // End of variables declaration//GEN-END:variables
}
